﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Drawing;
using System.Web.UI;
namespace Utility
{
    public abstract class JavaScript
    {
        /// <summary>
        /// ScriptManager Js提示窗口
        /// </summary>
        /// <param name="mUpdatePanel"></param>
        /// <param name="strMsg"></param>
        public static void JsAjaxMessageBox(UpdatePanel mUpdatePanel, string strMsg)
        {
            ScriptManager.RegisterStartupScript(mUpdatePanel, mUpdatePanel.GetType(), "js", "alert('" + strMsg + "');setDivResize();", true);
        }
        /// <summary>
        /// ScriptManager Js脚本发送
        /// </summary>
        /// <param name="mUpdatePanel"></param>
        /// <param name="strMsg"></param>
        public static void JsAjaxScript(UpdatePanel mUpdatePanel, string strMsg)
        {
            ScriptManager.RegisterStartupScript(mUpdatePanel, mUpdatePanel.GetType(), "js", strMsg, true);
        }
        /// <summary>
        /// Js提示窗口 -- 可能造成页面变形
        /// </summary>
        /// <example></example>
        /// <param name="strMsg">提示内容</param>
        public static void JsMessageBox(string strMsg)
        {
            HttpContext.Current.Response.Write(string.Format("<script language={1}javascript{1}>alert({1}{0}{1});</script>", strMsg, "'"));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strMsg"></param>
        /// <param name="Url"></param>
        public static void JsMessageBox(string strMsg, string Url)
        {
            HttpContext.Current.Response.Write(string.Format("<script language={1}javascript{1}>alert({1}{0}{1});top.location.href='{2}';</script>", strMsg, "'", Url));
        }

        /// <summary>
        /// Js脚本发送 -- 可能造成页面变形
        /// </summary>
        /// <param name="strMsg">alert('');window.close();location.href='';window.history.forward(1);</param>
        /// <returns>javascript字符串</returns>
        /// <example>Response.Write(CommFunction.JsScript(@"alert('');window.close();location.href='';"));</example>
        /// <remarks>无刷新返回前一页"window.location.href='" + Request.UrlReferrer + "';"</remarks>
        public static void JsScript(string strMsg)
        {
            HttpContext.Current.Response.Write(string.Format("<script language={1}javascript{1}>{0}</script>", strMsg, "'"));
        }
        /// <summary>
        /// Js提示窗口
        /// </summary>
        /// <param name="page"></param>
        /// <param name="strMsg"></param>
        public static void JsMessageBox(Page page, string strMsg)
        {
            page.ClientScript.RegisterStartupScript(HttpContext.Current.GetType(), "PopMessage", String.Format("<script language={1}javascript{1}>alert({1}{0}{1});</script>", strMsg, "\'"));
        }
        /// <summary>
        /// Js脚本发送
        /// </summary>
        /// <param name="page"></param>
        /// <param name="strMsg"></param>
        public static void JsScript(Page page, string strMsg)
        {
            page.ClientScript.RegisterStartupScript(HttpContext.Current.GetType(), "PopMessage", String.Format("<script language={1}javascript{1}>{0}</script>", strMsg, "\'"));
        }
        
    }
}
